package com.bps.zzant.model;

import static javax.persistence.GenerationType.IDENTITY;

import java.io.Serializable;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Table;

import org.hibernate.validator.constraints.NotEmpty;
import org.springframework.util.StringUtils;


@Entity
@Table(name = "customer")

public class Customer implements Serializable {
	/**
	 * 
	 */
	private static final long serialVersionUID = 8212151258133060106L;
	
	@Id
	@GeneratedValue(strategy = IDENTITY)
	@Column(name = "cus_id", unique = true, nullable = false)
	private int id;
	
	@Column(name = "customerName")
	@NotEmpty(message = "The Customer Name must not be blank.")
	private String customerName;
	
	@Column(name = "address1")
	private String address1;
	
	@Column(name = "address2")
	private String address2;
	
	@Column(name = "city")
	private String city;
	
	@Column(name = "contact")
	private String contact;
	
	@Column(name = "country")
	private String country;
	
	@Column(name = "email")
	private String email;
	
	@Column(name = "fax")
	private String fax;
	
	@Column(name = "firstName")
	private String firstName;
	
	@Column(name = "lastName")
	private String lastName;
	
	@Column(name = "midName")
	private String midName;
	
	@Column(name = "notes")
	private String notes;
	
	@Column(name = "phone1")
	private String phone1;
	
	@Column(name = "phone2")
	private String phone2;
	
	@Column(name = "resale_num")
	private String resaleNum;
	
	@Column(name = "sales_rep")
	private String salesRep;
	
	@Column(name = "state")
	private String state;
	
	@Column(name = "status")
	private String status;
	
	@Column(name = "taxable")
	private String taxable;
	
	@Column(name = "terms")
	private String terms;
	
	@Column(name = "zip")
	private String zip;

	public int getId() {
		return id;
	}

	public void setId(int id) {
		this.id = id;
	}

	public String getCustomerName() {
		return customerName;
	}

	public void setCustomerName(String customerName) {
		this.customerName = customerName;
	}

	public String getAddress1() {
		return address1;
	}

	public void setAddress1(String address1) {
		this.address1 = address1;
	}

	public String getAddress2() {
		return address2;
	}

	public void setAddress2(String address2) {
		this.address2 = address2;
	}

	public String getCity() {
		return city;
	}

	public void setCity(String city) {
		this.city = city;
	}

	public String getContact() {
		return contact;
	}

	public void setContact(String contact) {
		this.contact = contact;
	}

	public String getCountry() {
		return country;
	}

	public void setCountry(String country) {
		this.country = country;
	}

	public String getEmail() {
		return email;
	}

	public void setEmail(String email) {
		this.email = email;
	}

	public String getFax() {
		return fax;
	}

	public void setFax(String fax) {
		this.fax = fax;
	}

	public String getFirstName() {
		return firstName;
	}

	public void setFirstName(String firstName) {
		this.firstName = firstName;
	}

	public String getLastName() {
		return lastName;
	}

	public void setLastName(String lastName) {
		this.lastName = lastName;
	}

	public String getMidName() {
		return midName;
	}

	public void setMidName(String midName) {
		this.midName = midName;
	}

	public String getNotes() {
		return notes;
	}

	public void setNotes(String notes) {
		this.notes = notes;
	}

	public String getPhone1() {
		return phone1;
	}

	public void setPhone1(String phone1) {
		this.phone1 = phone1;
	}

	public String getPhone2() {
		return phone2;
	}

	public void setPhone2(String phone2) {
		this.phone2 = phone2;
	}

	public String getResaleNum() {
		return resaleNum;
	}

	public void setResaleNum(String resaleNum) {
		this.resaleNum = resaleNum;
	}

	public String getSalesRep() {
		return salesRep;
	}

	public void setSalesRep(String salesRep) {
		this.salesRep = salesRep;
	}

	public String getState() {
		return state;
	}

	public void setState(String state) {
		this.state = state;
	}

	public String getStatus() {
		return status;
	}

	public void setStatus(String status) {
		this.status = status;
	}

	public String getTaxable() {
		return taxable;
	}

	public void setTaxable(String taxable) {
		this.taxable = taxable;
	}

	public String getTerms() {
		return terms;
	}

	public void setTerms(String terms) {
		this.terms = terms;
	}

	public String getZip() {
		return zip;
	}

	public void setZip(String zip) {
		this.zip = zip;
	}

	public Customer(OrderGarment order) {
		this.address1 = order.getAddress1();
		this.address2 = order.getAddress2();
		this.city = order.getCity();
		this.contact = order.getContact();
		this.country = order.getCustomersCountry();
		this.customerName = order.getCustomerName();
		this.email = order.getEmail();
		this.fax = order.getFax();
		if(StringUtils.hasText(order.getContact())){
			
			try {
				String[] contactNameArray = order.getContact().split(" ");
				this.firstName = contactNameArray[0];
				
				if(contactNameArray.length>1){
				  this.lastName = contactNameArray[1];
				}
				
				if(contactNameArray.length>2){
					  this.midName = contactNameArray[1];
					  this.lastName = contactNameArray[2];
				}
			} catch (Exception e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		this.phone1 =order.getTel();
		this.phone2 = order.getCell();
		this.state = order.getState();
		this.zip = order.getZip();
	}

	public Customer() {
		super();
		// TODO Auto-generated constructor stub
	}
	
	
	
	
	
	
	
	
	
	
	
	
}
